
package com.hlkj.pay.service.order.impl;
/*
 * Hlpay-Plus aggregate payment system.
 * Copyright (c) 2024-2025 Hlpay Team Copyright has the right of final interpretation.
 */

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import com.hlkj.framework.common.pojo.LocalContext;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hlkj.pay.dto.LocalMerchantRequest;
import com.hlkj.pay.dto.order.OrderFundDto;
import com.hlkj.pay.dto.order.PayOrderFundDto;
import com.hlkj.pay.dto.order.PayOrderFundQueryDto;
import com.hlkj.pay.dto.order.RefundOrderFundDto;
import com.hlkj.pay.enums.CommonEnum;
import com.hlkj.pay.enums.PayOrderEnums;
import com.hlkj.pay.infrastructure.mapper.order.OrderFundDetailMapper;
import com.hlkj.pay.infrastructure.mapper.order.OrderFundMapper;
import com.hlkj.pay.infrastructure.mapper.order.PayOrderMapper;
import com.hlkj.pay.infrastructure.model.order.OrderFundDO;
import com.hlkj.pay.infrastructure.model.order.OrderFundDetailDO;
import com.hlkj.pay.infrastructure.model.order.PayOrderDO;
import com.hlkj.pay.service.CommonSnFilterService;
import com.hlkj.pay.service.order.IPayOrderFundService;
import com.hlkj.pay.util.MerchantUtils;
import com.hlkj.pay.vo.order.req.AcctPayOrderParamReq;
import com.hlkj.pay.vo.order.req.AcctRefundOrderParamReq;
import com.hlkj.pay.vo.order.req.OrderAccount;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * @author HlpayTeam
 * @date 2025/01/02 10:32
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class PayOrderFundServiceImpl extends CommonSnFilterService implements IPayOrderFundService {

    private final OrderFundMapper orderFundMapper;

    private final OrderFundDetailMapper orderFundDetailMapper;

    private final PayOrderMapper payOrderMapper;

    @Override
    public OrderFundDto addAcctPayInfo(AcctPayOrderParamReq acctPayOrderParamReq, List<PayOrderFundDto> payOrderFundDtos, PayOrderDO payOrderDO) {
        List<OrderFundDetailDO> payOrderFundList = new ArrayList<>();
        PayOrderEnums.SYSTEM_PROCESS_TYPE systemProcessType;
        boolean SYSTEM = false;
        switch (PayOrderEnums.FUND_PROCESS_TYPE.from(payOrderDO.getFundProcessType())) {
            case REAL_TIME:
                PayOrderEnums.CHANNEL_FUND_PROCESS_TYPE fundProcessType = PayOrderEnums.CHANNEL_FUND_PROCESS_TYPE.from(payOrderDO.getChannelCode());
                if (fundProcessType != null) {
                    // 只有一个取配置
                    if (fundProcessType.getSystemProcessTypes().size() == 1) {
                        systemProcessType = fundProcessType.getSystemProcessTypes().get(0);
                    }
                    else {
                        // 有多个 说明支持渠道自动分账 直接采用自动分账
                        systemProcessType = PayOrderEnums.SYSTEM_PROCESS_TYPE.CHANNEL;
                    }
                }
                else {
                    // 没有配置默认渠道自动分账
                    systemProcessType = PayOrderEnums.SYSTEM_PROCESS_TYPE.CHANNEL;
                }
                break;
            case DELAY_TIME:
                systemProcessType = PayOrderEnums.SYSTEM_PROCESS_TYPE.MERCHANT;
                break;
            case MERCHANT:
                systemProcessType = PayOrderEnums.SYSTEM_PROCESS_TYPE.SYSTEM;
                SYSTEM = true;
                break;
            default:
                return null;
        }

        payOrderFundDtos.stream().forEach(payOrderFundDto -> {
            OrderFundDetailDO orderFundDetailDO = new OrderFundDetailDO();
            orderFundDetailDO.setType(payOrderFundDto.getType());
            orderFundDetailDO.setDetailId(payOrderFundDto.getDetailId());
            orderFundDetailDO.setSuccessTime(payOrderFundDto.getSuccessTime());
            orderFundDetailDO.setAccountNo(payOrderFundDto.getAccountNo());
            orderFundDetailDO.setAmount(MerchantUtils.stringToBigDecimal(payOrderFundDto.getAmount()));
            orderFundDetailDO.setDescription(payOrderFundDto.getDescription());
            orderFundDetailDO.setFundStatus(payOrderFundDto.getFundStatus().getCode());
            orderFundDetailDO.setBatchNo(payOrderFundDto.getBatchNo());
            orderFundDetailDO.setName(payOrderFundDto.getName());
            orderFundDetailDO.setBatchNoDetail(payOrderFundDto.getBatchNoDetail());
            orderFundDetailDO.setFailReason(payOrderFundDto.getFailReason());
            payOrderFundList.add(orderFundDetailDO);
        });
        OrderFundDO orderFundDO = new OrderFundDO();
        orderFundDO.setPayOrderNo(payOrderDO.getPayOrderNo());
        orderFundDO.setSn(payOrderDO.getOrderSn());
        if (acctPayOrderParamReq != null) {
            orderFundDO.setMchAcctOrderNo(acctPayOrderParamReq.getMchAcctOrderNo());
            orderFundDO.setNotifyUrl(acctPayOrderParamReq.getNotifyUrl());
            orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.FUNDING.getCode());
            // 更新重新分账标识
            if(acctPayOrderParamReq.getAccRetry() != null && acctPayOrderParamReq.getAccRetry() == 1){
                // 原分账订单更新重新分账标识
                if(StrUtil.isNotEmpty(acctPayOrderParamReq.getOldBatchNo())){
                    LambdaQueryWrapperX<OrderFundDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
                    lambdaQueryWrapper.eqIfPresent(OrderFundDO::getBatchNo, acctPayOrderParamReq.getOldBatchNo());
                    OrderFundDO oldOrderFundDO = orderFundMapper.selectOne(lambdaQueryWrapper);
                    if(oldOrderFundDO != null){
                        OrderFundDO oldUpdateOrderFundDO = new OrderFundDO();
                        oldUpdateOrderFundDO.setId(oldOrderFundDO.getId());
                        oldUpdateOrderFundDO.setAccRetry(acctPayOrderParamReq.getAccRetry());
                        oldUpdateOrderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.CLOSE.getCode());
                        orderFundMapper.updateById(oldUpdateOrderFundDO);
                        log.info("原分账订单更新重新分账标识成功 data:{}",oldUpdateOrderFundDO);
                    }
                }
                // 新分账订单更新重新分账标识
                // orderFundDO.setAccRetry(acctPayOrderParamReq.getAccRetry());
            }
        }
        else {
            if(SYSTEM){
                orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.FUNDING.getCode());
            }else{
                orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.INIT.getCode());
            }
        }
        orderFundDO.setFundProcessType(payOrderDO.getFundProcessType());
        orderFundDO.setSystemProcessType(systemProcessType.getCode());
        orderFundDO.setFundType(CommonEnum.YES_NO_TYPE.NO.getCode());
        orderFundDO.setBatchNo(payOrderFundDtos.get(0).getBatchNo());
        orderFundMapper.insert(orderFundDO);
        orderFundDetailMapper.insertBatch(payOrderFundList);
        OrderFundDto orderFundDto = new OrderFundDto();
        orderFundDto.setOrderFund(orderFundDO);
        orderFundDto.setOrderFundDetailList(payOrderFundList);
        return orderFundDto;
    }

    @Override
    public OrderFundDto addAcctRefundInfo(AcctRefundOrderParamReq acctPayOrderParamReq, List<RefundOrderFundDto> payOrderFundDtos, PayOrderDO payOrderDO,PayOrderEnums.PAY_ORDER_FUND_STATUS payOrderFundStatus) {
        List<OrderFundDetailDO> payOrderFundList = new ArrayList<>();
        // 退款都是手动请求
        PayOrderEnums.SYSTEM_PROCESS_TYPE systemProcessType = PayOrderEnums.SYSTEM_PROCESS_TYPE.MERCHANT;
        payOrderFundDtos.stream().forEach(refundOrderFundDto -> {
            OrderFundDetailDO orderFundDetailDO = new OrderFundDetailDO();
            orderFundDetailDO.setAccountNo(refundOrderFundDto.getAccountNo());
            orderFundDetailDO.setAmount(MerchantUtils.stringToBigDecimal(refundOrderFundDto.getAmount()));
            orderFundDetailDO.setDescription(refundOrderFundDto.getDescription());
            orderFundDetailDO.setFundStatus(refundOrderFundDto.getFundStatus().getCode());
            orderFundDetailDO.setBatchNo(refundOrderFundDto.getBatchNo());
            orderFundDetailDO.setBatchNoDetail(refundOrderFundDto.getBatchNoDetail());
            orderFundDetailDO.setOrgBatchNoDetail(refundOrderFundDto.getOrgBatchNoDetail());
            orderFundDetailDO.setFailReason(refundOrderFundDto.getFailReason());
            payOrderFundList.add(orderFundDetailDO);
        });
        OrderFundDO orderFundDO = new OrderFundDO();
        orderFundDO.setPayOrderNo(payOrderDO.getPayOrderNo());
        orderFundDO.setSn(payOrderDO.getOrderSn());
        if (acctPayOrderParamReq != null) {
            orderFundDO.setMchAcctOrderNo(acctPayOrderParamReq.getMchAcctOrderNo());
            orderFundDO.setNotifyUrl(acctPayOrderParamReq.getNotifyUrl());
            orderFundDO.setMchAcctRefundOrderNo(acctPayOrderParamReq.getMchAcctRefundOrderNo());
        }
        orderFundDO.setFundProcessType(payOrderDO.getFundProcessType());
        orderFundDO.setSystemProcessType(systemProcessType.getCode());
        orderFundDO.setFundType(CommonEnum.YES_NO_TYPE.YES.getCode());
        LocalMerchantRequest localMerchantRequest = (LocalMerchantRequest) LocalContext.get();
        orderFundDO.setAppId(localMerchantRequest.getAppId());
        orderFundDO.setSignType(localMerchantRequest.getSignType());
        orderFundDO.setBatchNo(payOrderFundDtos.get(0).getBatchNo());
        if(payOrderFundStatus != null){
            orderFundDO.setFundStatus(payOrderFundStatus.getCode());
        }else{
            orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.REFUNDING.getCode());
        }
        orderFundMapper.insert(orderFundDO);
        orderFundDetailMapper.insertBatch(payOrderFundList);
        OrderFundDto orderFundDto = new OrderFundDto();
        orderFundDto.setOrderFund(orderFundDO);
        orderFundDto.setOrderFundDetailList(payOrderFundList);
        return orderFundDto;

    }

    @Override
    public List<OrderFundDetailDO> queryPayAcctInfo(String payOrderNo) {
        List<OrderFundDO> orderFundList = orderFundMapper.selectList(OrderFundDO::getPayOrderNo, payOrderNo);
        if (CollectionUtils.isEmpty(orderFundList)) {
            return Collections.emptyList();
        }
        List<String> batchNos = orderFundList.stream().map(orderFundDO -> orderFundDO.getBatchNo()).collect(Collectors.toList());
        PayOrderFundQueryDto payOrderFundQueryDto = new PayOrderFundQueryDto();
        payOrderFundQueryDto.setBatchNos(batchNos);
        return orderFundDetailMapper.selectList(buildDetailQueryWrapper(payOrderFundQueryDto));
    }

    @Override
    public OrderFundDO queryPayAcctInfo(String batchNo, String mchAcctOrderNo) {
        PayOrderFundQueryDto payOrderFundQueryDto = new PayOrderFundQueryDto();
        payOrderFundQueryDto.setBatchNo(batchNo);
        payOrderFundQueryDto.setMchAcctOrderNo(mchAcctOrderNo);
        return orderFundMapper.selectOne(buildQueryWrapper(payOrderFundQueryDto));
    }

    @Override
    public OrderFundDO queryRefundAcctInfo(String batchNo, String mchAcctRefundOrderNo) {
        PayOrderFundQueryDto payOrderFundQueryDto = new PayOrderFundQueryDto();
        payOrderFundQueryDto.setBatchNo(batchNo);
        payOrderFundQueryDto.setMchAcctRefundOrderNo(mchAcctRefundOrderNo);
        return orderFundMapper.selectOne(buildQueryWrapper(payOrderFundQueryDto));
    }

    @Override
    public void updateAcctInfoCallBack(PayOrderDO orderDb, List<OrderFundDetailDO> orderFunds) {
        List<OrderFundDetailDO> payOrderFundList = queryPayAcctInfo(orderDb.getPayOrderNo());
        if (CollectionUtils.isEmpty(payOrderFundList)) {
            return;
        }
        Map<String, OrderFundDetailDO> orderFundMap = payOrderFundList.stream().collect(Collectors.toMap(payOrderFundDO -> key(payOrderFundDO), Function.identity()));
        orderFunds.stream().forEach(orderFund -> {
            OrderFundDetailDO orderFundDO = orderFundMap.get(key(orderFund));
            if (orderFundDO != null) {
                orderFund.setId(orderFundDO.getId());
            }
        });
        orderFunds.stream().forEach(payOrderFundDO -> {
            if (payOrderFundDO.getId() != null) {
                orderFundDetailMapper.updateById(payOrderFundDO);
            }
        });
    }

    @Override
    public OrderFundDto updatePayFund(List<OrderFundDetailDO> orderFunds, String batchNo) {
        orderFundDetailMapper.updateBatch(orderFunds, orderFunds.size());
        List<OrderFundDetailDO> orderFundDetailList = queryAcctDetailInfo(batchNo);
        List<OrderFundDetailDO> successCollect = orderFundDetailList.stream()
                .filter(orderFundDetailDO -> PayOrderEnums.PAY_ORDER_FUND_STATUS.SUCCESS.getCode().equals(orderFundDetailDO.getFundStatus())).collect(Collectors.toList());
        // List<OrderFundDetailDO> failList = orderFundDetailList.stream()
        // .filter(orderFundDetailDO ->
        // PayOrderEnums.PAY_ORDER_FUND_STATUS.FAIL.getCode().equals(orderFundDetailDO.getFundStatus())).collect(Collectors.toList());
        List<OrderFundDetailDO> collect = orderFundDetailList.stream()
                .filter(orderFundDetailDO -> (!PayOrderEnums.PAY_ORDER_FUND_STATUS.FAIL.getCode().equals(orderFundDetailDO.getFundStatus())
                        && !PayOrderEnums.PAY_ORDER_FUND_STATUS.SUCCESS.getCode().equals(orderFundDetailDO.getFundStatus())))
                .collect(Collectors.toList());

        OrderFundDto orderFundDto = new OrderFundDto();
        orderFundDto.setOrderFundDetailList(orderFundDetailList);
        if (CollectionUtils.isEmpty(collect)) {
            OrderFundDO orderFundDO = queryPayAcctInfo(batchNo, null);
            OrderFundDO updateOrderFundDO = new OrderFundDO();
            updateOrderFundDO.setId(orderFundDO.getId());
            if (CollectionUtils.isEmpty(successCollect)) {
                updateOrderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.FAIL.getCode());
                orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.FAIL.getCode());
            }
            else {
                updateOrderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.SUCCESS.getCode());
                orderFundDO.setFundStatus(PayOrderEnums.PAY_ORDER_FUND_STATUS.SUCCESS.getCode());
            }
            orderFundMapper.updateById(updateOrderFundDO);
            orderFundDto.setOrderFund(orderFundDO);
        }
        return orderFundDto;
    }

    @Override
    public OrderFundDto queryAcctOrderFundDto(String batchNo) {
        LambdaQueryWrapperX<OrderFundDetailDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getBatchNo, batchNo);
        OrderFundDto orderFundDto = new OrderFundDto();
        orderFundDto.setOrderFund(orderFundMapper.selectOne(OrderFundDO::getBatchNo, batchNo));
        orderFundDto.setOrderFundDetailList(orderFundDetailMapper.selectList(lambdaQueryWrapper));
        return orderFundDto;
    }

    @Override
    public OrderFundDto queryAcctOrderFundDtoByPayOrderNo(String payOrderNo) {
        LambdaQueryWrapperX<OrderFundDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getPayOrderNo, payOrderNo);
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getFundType, CommonEnum.YES_NO_TYPE.NO.getCode());
        OrderFundDto orderFundDto = new OrderFundDto();
        List<OrderFundDO> orderFundList = orderFundMapper.selectList(lambdaQueryWrapper);
        if (CollUtil.isEmpty(orderFundList)) {
            return null;
        }
        OrderFundDO orderFundDO = orderFundList.get(0);
        orderFundDto.setOrderFund(orderFundDO);
        PayOrderFundQueryDto payOrderFundQueryDto = new PayOrderFundQueryDto();
        payOrderFundQueryDto.setBatchNo(orderFundDO.getBatchNo());
        orderFundDto.setOrderFundDetailList(orderFundDetailMapper.selectList(buildDetailQueryWrapper(payOrderFundQueryDto)));
        return orderFundDto;
    }

    @Override
    public List<OrderFundDetailDO> queryAcctDetailInfo(String batchNo) {
        LambdaQueryWrapperX<OrderFundDetailDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getBatchNo, batchNo);
        return orderFundDetailMapper.selectList(lambdaQueryWrapper);
    }

    @Override
    public List<OrderAccount> queryAcctAccountDetailInfo(String batchNo, Integer status,String failReason) {
        LambdaQueryWrapperX<OrderFundDetailDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getBatchNo, batchNo);
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getFundStatus, status);
        lambdaQueryWrapper.likeIfPresent(OrderFundDetailDO::getFailReason, failReason);
        List<OrderFundDetailDO> detailList = orderFundDetailMapper.selectList(lambdaQueryWrapper);

        List<OrderAccount> orderAccounts = new ArrayList<>();
        OrderAccount orderAccount = null;
        if(CollUtil.isNotEmpty(detailList)){
            for(OrderFundDetailDO detailDO:detailList){
                orderAccount = new OrderAccount();
                orderAccount.setAmount(detailDO.getAmount().toString());
                orderAccount.setName(detailDO.getName());
                orderAccount.setAccountNo(detailDO.getAccountNo());
                orderAccount.setDescription(detailDO.getDescription());
                orderAccounts.add(orderAccount);
            }
        }
        return orderAccounts;
    }

    @Override
    public List<OrderFundDO> queryPayAcctInfoList(PayOrderFundQueryDto payOrderFundQueryDto) {
        return orderFundMapper.selectList(buildQueryWrapper(payOrderFundQueryDto));
    }

    @Override
    public void updatePayFundStatus(Long id, PayOrderEnums.PAY_ORDER_FUND_STATUS payOrderFundStatus) {
        OrderFundDO orderFundDO = new OrderFundDO();
        orderFundDO.setId(id);
        orderFundDO.setFundStatus(payOrderFundStatus.getCode());
        orderFundMapper.updateById(orderFundDO);
    }

    @Override
    public void updatePayFundStatus(OrderFundDO orderFundDO) {
        orderFundMapper.updateById(orderFundDO);
    }

    @Override
    public void updatePayFundDetails(List<OrderFundDetailDO> orderFunds) {
        orderFundDetailMapper.updateBatch(orderFunds,orderFunds.size());
    }

    @Override
    public PageResult<OrderFundDO> queryPage(PayOrderFundQueryDto orderFundQueryDto) {
        return orderFundMapper.selectPage(orderFundQueryDto, buildQueryWrapper(orderFundQueryDto));
    }

    @Override
    public void delAcctDetail(String batchNoDetail) {
        OrderFundDetailDO orderFundDetailDO = queryAcctDetail(batchNoDetail);
        if(orderFundDetailDO != null){
            orderFundDetailMapper.deleteById(orderFundDetailDO.getId());
        }

    }

    @Override
    public OrderFundDetailDO queryAcctDetail(String batchNoDetail) {
        LambdaQueryWrapperX<OrderFundDetailDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getBatchNoDetail, batchNoDetail);
        OrderFundDetailDO orderFundDetailDO = orderFundDetailMapper.selectOne(lambdaQueryWrapper);
        return orderFundDetailDO;
    }

    String key(OrderFundDetailDO orderFundDO) {
        return orderFundDO.getAccountNo();
    }

    LambdaQueryWrapperX<OrderFundDO> buildQueryWrapper(PayOrderFundQueryDto payOrderFundQueryDto) {
        filterSn(payOrderFundQueryDto);
        LambdaQueryWrapperX<OrderFundDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getBatchNo, payOrderFundQueryDto.getBatchNo());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getPayOrderNo, payOrderFundQueryDto.getPayOrderNo());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getFundStatus, payOrderFundQueryDto.getFundStatus());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getFundProcessType, payOrderFundQueryDto.getFundProcessType());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getSystemProcessType, payOrderFundQueryDto.getSystemProcessType());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getMchAcctOrderNo, payOrderFundQueryDto.getMchAcctOrderNo());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getMchAcctRefundOrderNo, payOrderFundQueryDto.getMchAcctRefundOrderNo());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getFundType, payOrderFundQueryDto.getFundType());
        lambdaQueryWrapper.eqIfPresent(OrderFundDO::getSn,payOrderFundQueryDto.getSn());
        lambdaQueryWrapper.geIfPresent(OrderFundDO::getCreateTime, payOrderFundQueryDto.getStartQueryTime());
        lambdaQueryWrapper.leIfPresent(OrderFundDO::getCreateTime, payOrderFundQueryDto.getEndQueryTime());
        return lambdaQueryWrapper;
    }

    LambdaQueryWrapperX<OrderFundDetailDO> buildDetailQueryWrapper(PayOrderFundQueryDto payOrderFundQueryDto) {
        LambdaQueryWrapperX<OrderFundDetailDO> lambdaQueryWrapper = new LambdaQueryWrapperX<>();
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getBatchNo, payOrderFundQueryDto.getBatchNo());
        lambdaQueryWrapper.inIfPresent(OrderFundDetailDO::getBatchNo, payOrderFundQueryDto.getBatchNos());
        lambdaQueryWrapper.eqIfPresent(OrderFundDetailDO::getFundStatus, payOrderFundQueryDto.getFundStatus());
        lambdaQueryWrapper.geIfPresent(OrderFundDetailDO::getCreateTime, payOrderFundQueryDto.getStartQueryTime());
        lambdaQueryWrapper.leIfPresent(OrderFundDetailDO::getCreateTime, payOrderFundQueryDto.getEndQueryTime());
        return lambdaQueryWrapper;
    }
}
